package com.mf.controller;


import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import com.mf.entity.req.publicReq.ReqPublicIds;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.DtoSmashDetail;
import com.mf.entity.req.ReqSmashDetail;
import com.mf.service.ServiceSmashDetail;
import com.mf.entity.req.search.SearchReqSmashDetail;

import java.util.List;

/**
 * 粉碎明细
 *
 * @date 2025-04-21 09:19:55
 */
@RestController
@RequestMapping("smashdetail")
@Tag(name = "粉碎明细")
public class ControllerSmashDetail {
    @Resource
    private ServiceSmashDetail servicesmashDetail;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    public Result<Page<DtoSmashDetail>> findPage(@RequestBody SearchReqSmashDetail searchReqSmashDetail) {
        return Result.success(servicesmashDetail.findPageByParams(searchReqSmashDetail));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public Result<List<DtoSmashDetail>> list(@RequestBody SearchReqSmashDetail searchReqSmashDetail) {
        return Result.success(servicesmashDetail.findListByParams(searchReqSmashDetail));
    }

    @Operation(summary = "保存")
    @PostMapping("/save/{smashId}/{sourceId}/{workType}")
    public Result<Void> save(@RequestBody ReqPublicIds<Integer> detailIds, @PathVariable Integer smashId,
                             @PathVariable Integer sourceId,@PathVariable Integer workType) {
        servicesmashDetail.saveSmashDetail(detailIds.getIds(), smashId, sourceId, workType);
        return Result.success();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqSmashDetail reqSmashDetail) {
        servicesmashDetail.updateById(UtilConverter.convert(reqSmashDetail, DtoSmashDetail.class));
        return Result.success();
    }

    @Operation(summary = "删除")
    @PostMapping("/delete")
    public Result<Void> delete(@RequestBody ReqPublicIds<Integer> reqPublicIds) {
        servicesmashDetail.removeByIds(reqPublicIds.getIds());
        return Result.success();
    }

}
